<template>
  <div ref="chartRef" :style="{ height, width }"></div>
</template>
<script lang="ts" setup>
  import { onMounted, ref, Ref } from 'vue';
  import { useECharts } from '/@/hooks/web/useECharts';
  import { basicProps } from './props';
  import {defHttp} from "@/utils/http/axios";

  defineProps({
    ...basicProps,
  });

  const chartRef = ref<HTMLDivElement | null>(null);
  const { setOptions } = useECharts(chartRef as Ref<HTMLDivElement>);
  onMounted(() => {
    defHttp.get({ url: '/dashboard/analysis/growPlanData' }).then((response) => {
      console.log(response);
      let yData = [];
      let  xData = [];
      let  max = 0;
      response.forEach(item => {
        yData.push(item.month)
        xData.push(item.num);
        if (item.num>max){
          max = item.num;
        }
      })

      setOptions({
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            lineStyle: {
              width: 1,
              color: '#019680',
            },
          },
        },
        grid: { left: '1%', right: '1%', top: '2  %', bottom: 0, containLabel: true },
        xAxis: {
          type: 'category',
          data: yData,
        },
        yAxis: {
          type: 'value',
          max: max,
          splitNumber: 4,
        },
        series: [
          {
            data: xData,
            type: 'bar',
            barMaxWidth: 80,
          },
        ],
      });
    });
  });
</script>
